package cn.ronghuanet.auth.controller;

import cn.ronghuanet.auth.dto.LoginDTO;
import cn.ronghuanet.auth.service.ILoginService;
import cn.ronghuanet.base.util.AjaxResult;
import cn.ronghuanet.base.util.LoginContext;
import cn.ronghuanet.org.domain.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.UUID;


@RestController
public class LoginController {
    @Autowired
    private ILoginService service;
    @PostMapping("/Login")
    public AjaxResult Login(@RequestBody LoginDTO user){
        try {
            return AjaxResult.success(service.login(user));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    @PutMapping("/LoginOut")
    public AjaxResult LoginOut(HttpServletRequest request){
        try {
            String token = request.getHeader("token");
            LoginContext.loginMap.remove(token);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }
}
